package com.frinder.data.domain.web;

import com.frinder.base.global.Result;
import com.frinder.data.base.PageWrapper;
import com.frinder.data.base.PageInfo;
import com.frinder.data.domain.model.Camera;
import com.frinder.data.domain.service.ICameraService;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import javax.annotation.Resource;
import java.util.List;

/**
* Created by frinder on 2020/08/07.
*/
@RestController
@RequestMapping("/camera")
public class CameraController {

    @Resource
    private ICameraService cameraService;

    @ApiOperation(value = "添加 Camera")
    @PostMapping("/add")
    public Result add(@RequestBody Camera camera) {
        cameraService.save(camera);
        return Result.defSuccess();
    }

    @ApiOperation(value = "根据 id 删除 Camera")
    @GetMapping("/deleteById")
    public Result deleteById(@RequestParam String id) {
        cameraService.delete(id);
        return Result.defSuccess();
    }

    @ApiOperation(value = "根据 ids 批量删除 Camera")
    @GetMapping("/deleteByIds")
    public Result deleteByIds(@RequestParam List<String> ids) {
        cameraService.delete(ids);
        return Result.defSuccess();
    }

    @ApiOperation(value = "更新 Camera")
    @PostMapping("/update")
    public Result update(@RequestBody Camera camera) {
        cameraService.update(camera.getId(), camera);
        return Result.defSuccess();
    }

    @ApiOperation(value = "根据 id 查询 Camera")
    @GetMapping("/findById")
    public Result findById(@RequestParam String id) {
        Camera camera = cameraService.findById(id);
        return Result.dataSuccess(camera);
    }

    @ApiOperation(value = "根据 id 查询 Camera")
    @GetMapping("/findBySid")
    public Result findBySid(@RequestParam String sid) {
        Camera camera = cameraService.findBySid(sid);
        return Result.dataSuccess(camera);
    }

    @ApiOperation(value = "按条件分页查询 Camera")
    @PostMapping("/page")
    public Result page(@RequestBody PageWrapper<Camera> page) {
        PageInfo pageInfo = cameraService.page(page);
        return Result.dataSuccess(pageInfo);
    }
}
